package com.sunny.m1;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;
import java.util.concurrent.LinkedBlockingQueue;

public class Main {

    static ArrayList<Integer> dic = new ArrayList<>();

    static HashMap<Integer, ArrayList<Integer>> map = new HashMap<>();

    public static void main(String[] args) {



        int n;
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();

        boolean[] used = new boolean[n+1];
        for(int i=0;i<n-1;i++){
            int tmpa = scanner.nextInt();
            int tmpb = scanner.nextInt();
            if(map.containsKey(tmpa)){
                map.get(tmpa).add(tmpb);
            }else{
                ArrayList<Integer> list = new ArrayList<>();
                list.add(tmpb);
                map.put(tmpa, list);
            }

            if(map.containsKey(tmpb)){
                map.get(tmpb).add(tmpa);
            }else{
                ArrayList<Integer> list = new ArrayList<>();
                list.add(tmpa);
                map.put(tmpb, list);
            }
        }
//        System.out.println(map);

//        dfs(1, 0);


        LinkedBlockingQueue<Node> queue = new LinkedBlockingQueue<>();

        queue.offer(new Node(1, 0));
        while (!queue.isEmpty()){
            Node tmp = queue.poll();
            used[tmp.num] = true;
//            System.out.println(tmp.num + " " + tmp.layer);
            boolean flag = false;
            for(int next: map.get(tmp.num)){
                if(used[next])
                    continue;
                queue.offer(new Node(next, tmp.layer+1));
                flag = true;
            }
//            System.out.println(flag);
            if(!flag)
                dic.add(tmp.layer);
        }


//        System.out.println(dic);
        Collections.sort(dic);

//        System.out.println(dic);


        long res = 0;
        for(int i=0;i<dic.size();i++){
            if(i != dic.size()-1)
                res += 2L*dic.get(i);
            else
                res += (long)dic.get(i);
        }
        System.out.println(res);

    }

//    public static void dfs(int num, int layer){
//
////        System.out.println(num + " " + layer);
//
//        boolean flag = false;
//        used[num] = true;
//
//        for(int tmp: map.get(num)){
//            if(used[tmp])
//                continue;
//            dfs(tmp, layer+1);
//            flag = true;
//        }
//
//        if(!flag)
//            dic.add(layer);
//
//
//    }

}


class Node{
    int num;
    int layer;

    public Node(int num, int layer) {
        this.num = num;
        this.layer = layer;
    }
}